package com.probiz.estore.system.dao.impl;

import java.util.List;

import com.probiz.estore.common.model.system.AppResource;
import com.probiz.estore.core.dao.impl.HibernateGenericDaoImpl;
import com.probiz.estore.core.model.BaseObject;
import com.probiz.estore.system.dao.AppResourceDao;

/**
 * Dao implementation for AppResource.
*/
public class AppResourceDaoImpl extends HibernateGenericDaoImpl<AppResource> implements AppResourceDao {
	protected void initFilterHqlMap() {
		filterHqlMap.put(BaseObject.FilterHqlName.DEFAULT, "from AppResource s where s.belongTo=? order by s.resourceString");
	}
	
	public boolean isPatternExist(String patternString, Integer excludeResourceId){
		String hql = "from AppResource s where s.resourceString=?";
		
		if(excludeResourceId!=null){
			hql += " and resourceId!=?";
			return this.countByHql(hql, patternString, excludeResourceId)>0;
		}
		
		return this.countByHql(hql, patternString)>0;
	}
	
	@Override
	public List<AppResource> listAll(){
		return this.listAllOrdered("resourceString", false);
	}
}
